const router = require('koa-router')()
const menus = require('../model/menuSchema')
const utils = require('../utils/utils')
router.prefix('/menu')
router.get('/list', async (ctx) => {
  try {
    const role = ctx.request.query.role
    const res = await menus.find({
      roles: { $elemMatch: { $eq: parseInt(role) } }
    })
    if (res) {
      ctx.body = utils.success(res)
    } else {
      ctx.body = utils.fail('数据检索异常')
    }
  } catch (error) {
    ctx.body = utils.fail(error.msg)
  }
})
module.exports = router
